package com.easymin.weixin.controller.web;

import com.easymin.weixin.common.DataForm;
import com.easymin.weixin.common.DataGrid;
import com.easymin.weixin.entity.WxAccount;
import com.easymin.weixin.manager.WxAccountManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
@RequestMapping("wxAccounts")
public class WxAccountController {

  @Autowired
  private WxAccountManager wxAccountManager;
  
  
  @RequestMapping(value = {"", "/"}, method = RequestMethod.GET)
  public String index() {

    return "wxAccount/list";
  }

  @RequestMapping(value = {"datagrid"}, method = RequestMethod.GET)
  public @ResponseBody DataGrid<Map<String, Object>> list(@RequestParam("page") int page,
      @RequestParam("rows") int rows) {
    return wxAccountManager.findAll(page, rows);
  }
  
  
  
  @RequestMapping(value = {"", "/"}, method = RequestMethod.POST)
  public @ResponseBody DataForm<WxAccount> add(@ModelAttribute WxAccount wxAccount) {

    return wxAccountManager.insert(wxAccount);
  }
  
  
  @RequestMapping(value = "{id}", method = RequestMethod.GET)
  public @ResponseBody WxAccount find(@PathVariable("id") Long id) {
    return wxAccountManager.fetch(id);
  }

  @RequestMapping(value = "{id}", method = RequestMethod.PATCH)
  public @ResponseBody DataForm<WxAccount> update(@ModelAttribute WxAccount wxAccount) {
    return wxAccountManager.updateByPrimaryKey(wxAccount);
  }

  @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
  public @ResponseBody DataForm<WxAccount> delete(@PathVariable("id") Long id) {

    return wxAccountManager.deleteByPrimaryKey(id);
  }
}
